var L = require('./leafletwx')

export function createMap(contanter, options, callback) {
  wx.createSelectorQuery().in(contanter).select('#leafletwx-overlay-canvas').fields({ 
      node: true, 
      size: true 
    }).exec((res) => { 
      var width = res[0].width; 
      var height = res[0].height; 
      global.wx.overlayCanvas = res[0].node;
      options ??= {};
      options.preferCanvas = true
      let map = L.map(contanter, options);
      global.wx.overlayCanvas.setPosition = 'setOverlayCanvasPosition';
      global.wx.overlayCanvas.getPosition = 'getOverlayCanvasPosition';
      global.wx.overlayCanvas.addEventListener = function(event, func, useCapture) {
          global.wxDOM.addEventListener(global.wx.overlayCanvas, event, func, useCapture);
      },
      global.wx.overlayCanvas.removeEventListener = function(event, func, useCapture) { 
          global.wxDOM.removeEventListener(global.wx.overlayCanvas, event, func, useCapture);
      }
      if (callback != null) callback(map);
    })
};